import requests

def get_remote_link_duration(link_url):
    try:
        # 发送HTTP请求以获取链接文件的信息
        response = requests.head(link_url)

        # 检查请求是否成功
        if response.status_code == 200:
            # 获取链接文件的修改时间（如果服务器提供的话）
            modification_time = response.headers.get("Last-Modified")
            if modification_time:
                # 解析HTTP标头中的时间戳
                from dateutil import parser
                modified_time = parser.parse(modification_time)
                return modified_time
            else:
                print("服务器未提供修改时间信息。")
        else:
            print(f"HTTP请求失败，状态码: {response.status_code}")
            return None
    except requests.exceptions.RequestException as e:
        print(f"无法获取远程链接文件的时长: {e}")
        return None


# 用法示例
def main():
    # 用法示例
    link_url = ("https://sgm-ai-asr.oss-cn-hangzhou.aliyuncs.com/ml/prod/20231013"
                "/lt3_MLR3012CKM0NEK9A_customer20231013094537.wav")
    duration = get_remote_link_duration(link_url)
    if duration:
        print(f"远程链接文件的时长为: {duration}")


if __name__ == '__main__':
    main()